<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>

<style>

table label.error {
    margin-left: 5px;
    width: auto;
    display: inline;
    color: red;
}

</style>
<script>
$(document).ready(
					function() {
						$("#div1").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择负责人',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							
								  if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
									  layer.alert("请选择一项", {icon: 6});
									 return false;
								  }
							 
								   var formSelect = document.getElementById("fromSelect");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 6});
								      return false;
								    }
								    
							     $("#xm").val($("#fromSelect").find("option:selected").text());
							     $("#principal").val($("#fromSelect").val());
							     $(this).dialog('close');
							  
							}
						  }
						});

					});
	function showdiv() {
		$('#div1').dialog('open');
	}
</script>
</head>
<body>
     <form action="#" name="Form" id="Form" method="post">
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="80%">
			<tr>
				<td class="table-header" colspan="4">项目管理</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>项目名：</td>
				<td class="table-contentTD" style="width: 70%">
				<input type="text" id="projectName" name="projectName"  placeholder="项目名"   autocomplete="off" maxlength="100" class="required inputText" /></td>
			</tr>
			<tr>
			
			 <td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>周期：</td>
				<td class="table-contentTD">
				<input type="text" id="cycle" name="cycle"  placeholder="周期"   autocomplete="off" maxlength="100" class="required inputText" /></td>
			</tr>
			
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>完成时间：</td>
				<td class="table-contentTD">
				<input name="completeDate" id="completeDate" placeholder="完成时间"   autocomplete="off"
									class="Wdate required inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
			</tr>
			
		    <tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>负责人：</td>
				<td class="table-contentTD" style="width: 70%">
			    <input type="hidden" name="principal" id="principal"/>
				<input type="text" id="xm" name="xm"  placeholder="负责人"  readonly="readonly"  class="inputText required" />
				<input type="button" id="optionBtn" value="选择" class="inputButton"
					onclick="javascript:showdiv();" /></td>
			</tr>
			
			<tr>
				<td class="table-titleTD">备注：</td>
				<td class="table-contentTD" colspan="3" style="width: 100%"><textarea style="width: 90%;height: 80px;" name="other"  placeholder="备注" id="other" maxlength="2000" ></textarea></td>
			</tr>
		</table>
		<br />
		
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
			    <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_XMG\")%>" key="add">		
			    <td><input type="button" id="btnSave" class="inputButton"
					style="text-align: center;" value="保存" /></td>
				<td><input type="button" id="btnSaveContinue" class="inputButton"
					style="text-align: center;" value="保存并新增" /></td>
					</kl:permission>
				<td><input type="button" id="Cancel" class="inputButton"
					style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton"
					value="返回" style="text-align: center;" /></td>
			</tr>
		</table>
		
      <div id="div1" style="display: none;">
			<table cellpadding="0" cellspacing="0" border="0" class="table-border">
				  <tr>
				  	 <td style="clear:both; width: 70%">
				  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
				  	   <br/><label style="color:red;">未选中:</label><br/>
				  	   <select name="fromSelect" id="fromSelect" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
							ondblclick="moveField('fromSelect','toSelect');">
											<c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach>
						</select>
							<select name="sourseFromSelect2" id="sourseFromSelect2"   multiple="false" style="width: 220px; height: 150px; display: none;" >
										  <c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach>
  	    </select>
						
					 </td>
  	              </tr>
			</table>
		</div>
		
		<script>
		    
			$(document).ready(function() {
				var _form=$("#Form").validate();
				$("#btnSave").click(function() {
					if(_form.form()){
						validataSave();
					}
				});
				
				$("#btnSaveContinue").click(function() {
					if(_form.form()){
						validataSaveContinue();
					}
				});
				
				function validataSave(){
				  	$.ajax({
						  type: 'POST',
						  url: "${basePath}/project/validation",
					      data:{projectName : $('#projectName').val(),id:null},
						  success:function(data){
							  /*  var json = eval("(" + data + ")"); */
							   var json = typeof data=='string'?JSON.parse(data) :data;
							   if(json.msg==-99){
								     layer.alert('服务器异常', {icon: 5});
								     return false;
							   }else if(json.msg!=0){
								     layer.alert('项目名称已经存在请重新输入', {icon: 5});
								     return false;
							   }else{
								    document.Form.action ="${basePath}/project/add";
									document.Form.submit();
							   }   
						  }
						});	
				}
				
				
				function validataSaveContinue(){
				  	$.ajax({
						  type: 'POST',
						  url: "${basePath}/project/validation",
					      data:{projectName : $('#projectName').val(),id:null},
						  success:function(data){
							   var json = typeof data=='string'?JSON.parse(data) :data;
						 /*   var json = eval("(" + data + ")"); */
						   if(json.msg==-99){
							     layer.alert('服务器异常', {icon: 5});
							     return false;
						   }else if(json.msg!=0){
							     layer.alert('项目名称已经存在请重新输入', {icon: 5});
							     return false;
						   }else{
							    document.Form.action ="${basePath}/project/addSaveContinue";
								document.Form.submit();
						   }   
						  }
						});	
				}
				$("#returnBut").click(function() {
		 			 window.location.href='${basePath}/project/index';
		 		});
				
				$("#Cancel").click(function() {
					   window.location.href = "${basePath}/project/addInInt";
		 		});
			});
			
			 if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			  } 
		</script>
	</form>
</body>
</html>
